<?php

/*
 * Created on Dec 13, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

$conn = mysql_connect("localhost", "root", "bytewalla5");

$pagesize = 10;
mysql_select_db("ssa", $conn);

if (isset ($_GET['keyword'])){
	$sqlcount = "select count(*) from patient where ".$_GET['keyword_type']." like '%".$_GET['keyword']."%'";
	$sqlquery = "select * from patient where ".$_GET['keyword_type']." like '%".$_GET['keyword']."%' order by id desc ";
}else{
	$sqlcount = "select count(*) from patient";
	$sqlquery = "select * from patient order by id desc ";//keep a space in the later
}
//echo $sqlcount;
$sqlexport = $sqlquery;

$rs = mysql_query($sqlcount, $conn);
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];

$pages = intval($numrows / $pagesize);
if ($numrows % $pagesize)
	$pages++;

if (isset ($_GET['page'])) {
	$page = intval($_GET['page']);
} else {
	$page = 1;
}

$offset = $pagesize * ($page -1);

$sqlquery .= " limit ".$offset.", ".$pagesize;
//echo $sqlquery;
$rs = mysql_query($sqlquery, $conn);

?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Query info</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.6.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_400.font.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_700.font.js"></script>
<script type="text/javascript" src="js/tabs.js"></script>

  <!--[if lt IE 9]>
  	<script type="text/javascript" src="js/html5.js"></script>
	<style type="text/css">
		.bg{ behavior: url(js/PIE.htc); }
	</style>
  <![endif]-->
	<!--[if lt IE 7]>
		<div style=' clear: both; text-align:center; position: relative;'>
			<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0"  alt="" /></a>
		</div>
	<![endif]-->

</head>

<body id="page2">
	<div class="body1">
	<div class="body2">
	<div class="body5">
		<div class="main">
<!-- header -->
			<header>
				<div class="wrapper">
				<h1><a href="index.html" id="logo">Progress Business Company</a></h1>
				<nav>
					<ul id="menu">
						<li id="nav1"><a href="index.html">Home<span>Welcome!</span></a></li>
						<li id="nav2" class="active"><a href="ssa.html">SSA<span>Fresh</span></a></li>
						<li id="nav3"><a href="nmt.html">NMT<span>for you</span></a></li>
						<li id="nav4"><a href="wsn.html">WSN<span>The best</span></a></li>
						<li id="nav5"><a href="Contacts.html">Contacts<span>Our Address</span></a></li>
					</ul>
				</nav>
				</div>
			</header><div class="ic">More Website Templates  at TemplateMonster.com!</div>
<!-- header end-->
		</div>
	</div>
	</div>
	</div>
	<div class="body3">
		<div class="main">
<!-- content -->
			<article id="content">
			<div class="wrapper tabs">
     				<section class="col1">
     				<h2 class="under">Search Record</h2>
					<form id="ContactForm" action="query.php" method="get">
					 	serach by
					 	<select id="keyword_type" name="keyword_type">
								<option value="caseid">caseid</option>
								<option value="firstname">first name</option>
								<option value="lastname">last name</option>
								<option value="prevdisease">disease</option>
								<option value="age">age</option>
                                                                <option value="gender">gender</option>
						</select>
					 	<input  class="input" type="input" name="keyword" />
					 	<a href="#" onClick="document.getElementById('ContactForm').submit()">Search</a>
					 	
					</form>
					
			<div>
							 
				<table id="customers">
					<tr>
					  <th>caseid</th>
					  <th>firstname</th>
					  <th>Allergy</th>
                                          <th>Disease</th>
					</tr>
					<?php 
     			if ($myrow = mysql_fetch_array($rs)) {
					$i = 0;
     				do { 
							$i++;
							//echo $myrow["caseid"]." ".$myrow["firstname"];
							?>
							<tr>
							<td><a href="caseDetail?id=<?=$myrow["id"];?>"><?=$myrow["caseid"];?></a></td>
								<td><?=$myrow["firstname"];?></td>
								<td><?=$myrow["allergy"];?></td>
                                                                <td><?=$myrow["prevdisease"];?></td>
							<tr>

							<?php
     						
					} while ($myrow = mysql_fetch_array($rs)); 
				}?> 
				
					
				</table>
				<a href="exportData.php?export=<?=$sqlexport?>">Export</a>
							 
     			
			<div align='center'>
			<?php 
				for ($i=1;$i< $page;$i++) 
					echo "<a href='query.php?page=".$i."'>[".$i ."]</a>"; 
				echo "[".$page."]"; 
				for ($i=$page+1;$i<=$pages;$i++)
					echo "<a href='query.php?page=".$i."'>[".$i ."]</a>"; 
				
				?>
			<br/>
			total <?=$pages ?> pages(<?=$page ?>/<?=$pages ?>)
			</div>
			
		</div>


							
					</section>


				</div>

			</article>
		</div>
	</div>
	<div class="body4">
		<div class="main">
			<article id="content2">
				<div class="wrapper">
					<section class="col3">
						<h4>Why Us?</h4>
						<ul class="list1">
							<li><a href="#">Lorem ipsum dolor sit</a></li>
							<li><a href="#">Dmet, consectetur</a></li>
							<li><a href="#">Adipisicing elit eiusmod </a></li>
							<li><a href="#">Tempor incididunt ut</a></li>
						</ul>
					</section>
					<section class="col3 pad_left2">
						<h4>Address</h4>
						<ul class="address">
							<li><span>Country:</span>Sweden</li>
							<li><span>City:</span>Stockholm</li>
							<li><span>Phone:</span></li>
							<li><span>Email:</span><a href="mailto:">mail@bytewalla.com</a></li>
						</ul>
					</section>
					<section class="col3 pad_left2">
						<h4>Follow Us</h4>
						<ul id="icons">
							<li><a href="#"><img src="images/icon1.jpg" alt="">Facebook</a></li>
							<li><a href="#"><img src="images/icon2.jpg" alt="">Twitter</a></li>

						</ul>
					</section>

				</div>
			</article>
<!-- content end -->
		</div>
	</div>
		<div class="main">
<!-- footer -->
   
<!-- footer end -->
		</div>
<script type="text/javascript"> Cufon.now(); </script>
<script>
	$(document).ready(function() {
		tabs.init();
	})
</script>
</body>
</html>

